package jrdcom.com.jrdcommonknowledge.Fragments;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.lang.reflect.Array;

import butterknife.Bind;
import butterknife.ButterKnife;
import jrdcom.com.jrdcommonknowledge.Fragments.Serialize.serializeFragments;
import jrdcom.com.jrdcommonknowledge.JrdCommon;
import jrdcom.com.jrdcommonknowledge.R;

/**
 * Created by longcheng on 2017/3/28.
 */

public class MainFragments extends Fragment {
    public static final String TAG = MainFragments.class.getSimpleName();
    @Bind(R.id.fragment_list)
    ListView fragmentList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.layout_fragment_main, container, false);
        ButterKnife.bind(this, v);

        ArrayAdapter arrayAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, JrdCommon.ListArray);
        fragmentList.setAdapter(arrayAdapter);
        fragmentList.setOnItemClickListener(jrdOnItemClick);
        return v;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    private AdapterView.OnItemClickListener jrdOnItemClick = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position)
            {
                case  0:
                    //Go to main Fragment
                    getFragmentManager()
                            .beginTransaction()
                            .replace(R.id.main_fragment, new serializeFragments())
                            .addToBackStack(serializeFragments.TAG)
                            .commit();
                    break;
                case 1:

                    break;

            }
        }
    };

}
